﻿using System.Web;
using RbacLib.Models;

namespace RBAC.Web.Utilities
{
    public class RbacUtil
    {
        private const string DisabledButton = "disabled='disabled'";
        private static readonly string EnabledButton = string.Empty;

        private const string HideMenu = "style = 'display: none;'";
        private static readonly string ShowMenu = string.Empty;

        #region User
        public static HtmlString SetUserMenu(UserProfile userProfile)
        {
            var result = new HtmlString(HideMenu);

            var criteria = new PrivilegeClassCriteria
            {
                DomainName = RbacEnum.Domain.User.ToString(),
                UserProfile = userProfile
            };

            //var privilege = RbacLib.Service.PrivilageClass(criteria).Data;
            //if (privilege) { result = new HtmlString(ShowMenu); }
            //result = new HtmlString(privilege);
            result = RbacLib.Service.PrivilageClass(criteria).Data;

            return result;
        }

        public static string SetAddUserButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.User.ToString(),
                FunctionName = (int)RbacEnum.Function.Add,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            //if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }

        public static string SetUpdateUserButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.User.ToString(),
                FunctionName = (int)RbacEnum.Function.Update,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            //if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }

        public static string SetDeleteUserButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.User.ToString(),
                FunctionName = (int)RbacEnum.Function.Delete,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            //if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }

        public static string SetSearchUserButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.User.ToString(),
                FunctionName = (int)RbacEnum.Function.Search,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            //if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }
        #endregion

        #region Role
        public static HtmlString SetRoleMenu(UserProfile userProfile)
        {
            var result = new HtmlString(HideMenu);

            var criteria = new PrivilegeClassCriteria
            {
                DomainName = RbacEnum.Domain.Role.ToString(),
                UserProfile = userProfile
            };

            //var privilege = RbacLib.Service.PrivilageClass(criteria).Data;
            //if (privilege) { result = new HtmlString(ShowMenu); }
           // result = new HtmlString(privilege);
            result = RbacLib.Service.PrivilageClass(criteria).Data;

            return result;
        }

        public static string SetAddRoleButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Role.ToString(),
                FunctionName = (int)RbacEnum.Function.Add,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            ////if (privilege) { result = EnabledButton; }
            result = privilege;

            return result;
        }

        public static string SetUpdateRoleButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Role.ToString(),
                FunctionName = (int)RbacEnum.Function.Update,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            ////if (privilege) { result = EnabledButton; }
            result = privilege;

            return result;
        }

        public static string SetDeleteRoleButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Role.ToString(),
                FunctionName = (int)RbacEnum.Function.Delete,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            ////if (privilege) { result = EnabledButton; }
            result = privilege;

            return result;
        }

        public static string SetSearchRoleButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Role.ToString(),
                FunctionName = (int)RbacEnum.Function.Search,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            ////if (privilege) { result = EnabledButton; }
            result = privilege;

            return result;
        }
        #endregion

        #region Permission
        public static HtmlString SetPermissionMenu(UserProfile userProfile)
        {
            var result = new HtmlString(HideMenu);

            var criteria = new PrivilegeClassCriteria
            {
                DomainName = RbacEnum.Domain.Permission.ToString(),
                UserProfile = userProfile
            };

            //var privilege = RbacLib.Service.PrivilageClass(criteria).Data;
            ////if (privilege) { result = new HtmlString(ShowMenu); }
            //result = new HtmlString(privilege);
            result = RbacLib.Service.PrivilageClass(criteria).Data;

            return result;
        }

        public static string SetAddPermissionButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Permission.ToString(),
                FunctionName = (int)RbacEnum.Function.Add,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            ////if (privilege) { result = EnabledButton; }
            result = privilege;

            return result;
        }

        public static string SetUpdatePermissionButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Permission.ToString(),
                FunctionName = (int)RbacEnum.Function.Update,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            ////if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }

        public static string SetDeletePermissionButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Permission.ToString(),
                FunctionName = (int)RbacEnum.Function.Delete,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            ////if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }

        public static string SetSearchPermissionButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Permission.ToString(),
                FunctionName = (int)RbacEnum.Function.Search,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            //if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }
        #endregion

        #region Function
        public static HtmlString SetFunctionMenu(UserProfile userProfile)
        {
            var result = new HtmlString(HideMenu);

            var criteria = new PrivilegeClassCriteria
            {
                DomainName = RbacEnum.Domain.Function.ToString(),
                UserProfile = userProfile
            };

            //var privilege = RbacLib.Service.PrivilageClass(criteria).Data;
            ////if (privilege) { result = new HtmlString(ShowMenu); }
            //result = new HtmlString(privilege);
            result = RbacLib.Service.PrivilageClass(criteria).Data;

            return result;
        }

        public static string SetAddFunctionButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Function.ToString(),
                FunctionName = (int)RbacEnum.Function.Add,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            //if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }

        public static string SetUpdateFunctionButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Function.ToString(),
                FunctionName = (int)RbacEnum.Function.Update,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            //if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }

        public static string SetDeleteFunctionButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Function.ToString(),
                FunctionName = (int)RbacEnum.Function.Delete,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            //if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }

        public static string SetSearchFunctionButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Function.ToString(),
                FunctionName = (int)RbacEnum.Function.Search,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            //if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }
        #endregion

        #region Domain
        public static HtmlString SetDomainMenu(UserProfile userProfile)
        {
            var result = new HtmlString(HideMenu);

            var criteria = new PrivilegeClassCriteria
            {
                DomainName = RbacEnum.Domain.Domain.ToString(),
                UserProfile = userProfile
            };

            //var privilege = RbacLib.Service.PrivilageClass(criteria).Data;
            ////if (privilege) { result = new HtmlString(ShowMenu); }
            //result = new HtmlString(privilege);
            result = RbacLib.Service.PrivilageClass(criteria).Data;

            return result;
        }

        public static string SetAddDomainButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Domain.ToString(),
                FunctionName = (int)RbacEnum.Function.Add,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            //if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }

        public static string SetUpdateDomainButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Domain.ToString(),
                FunctionName = (int)RbacEnum.Function.Update,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            //if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }

        public static string SetDeleteDomainButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Domain.ToString(),
                FunctionName = (int)RbacEnum.Function.Delete,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            //if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }

        public static string SetSearchDomainButton(UserProfile userProfile)
        {
            var result = DisabledButton;

            var criteria = new PrivilegeFunctionCriteria
            {
                DomainName = RbacEnum.Domain.Domain.ToString(),
                FunctionName = (int)RbacEnum.Function.Search,
                UserProfile = userProfile
            };

            var privilege = RbacLib.Service.PrivilegeFunction(criteria).Data;
            //if (privilege) { result = EnabledButton; }
            result = privilege;
            return result;
        }
        #endregion
    }
}